package com.xawx.hch.finances.util;

import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
import com.xawx.hch.finances.activity.R;
import com.xawx.hch.finances.bean.AppendOccurrenceBean;
/**
 * Title: LoginActivity
 * Description: 
 * Copyright: Copyright (c) 2012
 * Company: Xawx Teachnology
 * CreateTime: Mar 6, 2012 10:40:36 AM
 * 
 * @author 
 * @version %A%, %B%
 * @since JDK1.6
 */
public class SortListViewAdapter extends BaseAdapter{
	private ArrayList<AppendOccurrenceBean> mList;
	private LayoutInflater inflater = null;
	private CheckBox mcheckbox = null;
	public Context context;
	public  String ids=""; 
	private TextView sort_item_inOrOut,sort_item_sort;
	
	public SortListViewAdapter(Context c,ArrayList<AppendOccurrenceBean> list) {
		System.out.println("ListViewAdapter2");
		this.mList = list;
		this.context= c;
		inflater = LayoutInflater.from(c);
	}
	
	public SortListViewAdapter(Context c){
		System.out.println("ListViewAdapter1");
		this.context= c;
		inflater = LayoutInflater.from(c);
	}

	public int getCount() {
		System.out.println("getCount");
		if( null != mList)
			return mList.size();
		return 0;
	}

	public Object getItem(int position) {
		System.out.println("getItem");
		if(null != mList){
			return mList.get(position);
		}
		return null;
	}

	public long getItemId(int position) {
		System.out.println("getItemId");
		return position;
	}
	
	public View getView(int position, View convertView, ViewGroup parent){
		System.out.println("getView");
		AppendOccurrenceBean appendBean = (AppendOccurrenceBean) mList.get(position);			
			convertView = inflater.inflate(R.layout.sort_select_item,null);
			mcheckbox = (CheckBox) convertView.findViewById(R.id.sort_item_checkbox);
			sort_item_inOrOut = (TextView)convertView.findViewById(R.id.sort_item_inOrOut);
			sort_item_sort = (TextView)convertView.findViewById(R.id.sort_item_sort);
			sort_item_inOrOut.setText(appendBean.getOutOrIn());
			sort_item_sort.setText(appendBean.getOccurrence());
			mcheckbox.setId(appendBean.getId());
			mcheckbox.setFocusable(false);
			if(mcheckbox.isFocused()){
			}
			mcheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {
					if(isChecked){
						System.out.println("buttonView.getId():"+(buttonView.getId()));
						ids += buttonView.getId()+",";
						System.out.println("ids:"+ids);
					}else{
						
						 ids = ids.replace(buttonView.getId()+",","");
						System.out.println("idsqqq:"+ids);
					}
				}
			});

		return convertView;
	}

}
